﻿using System.Web.Mvc;

namespace Nasa8x.Mvc.Helpers.Attributes
{
    public class IsPostbackFromThisSiteAttribute : AuthorizeAttribute
    {

        public override void OnAuthorization(AuthorizationContext _filterContext)
        {

            if (_filterContext.HttpContext != null)
            {
                if (_filterContext.HttpContext.Request.UrlReferrer == null || _filterContext.HttpContext.Request.Url==null)
                    throw new System.Web.HttpException("Invalid submission");
                if (_filterContext.HttpContext.Request.UrlReferrer.Host != _filterContext.HttpContext.Request.Url.Host)
                    throw new System.Web.HttpException("This form wasn’t submitted from this site!");

                
            }

            //base.OnAuthorization(filterContext);

        } 
    }
}
